package antoine.ear.exo.intervalles;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Track;

import antoine.ear.exo.Exo;
import antoine.ear.generator.NoteGenerator;

public class TierceMUp extends Exo {

	public TierceMUp(int tempo, int octave) {
		super(tempo, octave);
	}

	public String getPrintableResult() {
		return null;
	}

	public void generate() throws Exception {
		try {
			Sequence seq = new Sequence(Sequence.PPQ, 1);
			int tick;
			for (int i=0; i<30; i++){
				tick = i*4;
				Track track = seq.createTrack();
				int note = NoteGenerator.generateNote(this.getOctave());
				track.add(createNoteOnEvent(note, tick));
				track.add(createNoteOffEvent(note, tick+1));
				track.add(createMetaMessOnEvent(note, tick, ACTIVATENOTE));
				track.add(createMetaMessOnEvent(note, tick+1, DESACTIVATENOTE));
				
				track.add(createNoteOnEvent(note+4, tick+1));
				track.add(createNoteOffEvent(note+4, tick+2));
				track.add(createMetaMessOnEvent(note+4, tick+1, ACTIVATENOTE));
				track.add(createMetaMessOnEvent(note+4, tick+2, DESACTIVATENOTE));
				
				track.add(createNoteOnEvent(note, tick+2));
				track.add(createNoteOnEvent(note+4, tick+2));
				track.add(createNoteOffEvent(note, tick+3));
				track.add(createNoteOffEvent(note+4, tick+3));
				track.add(createMetaMessOnEvent(note+4, tick+2, ACTIVATENOTE));
				track.add(createMetaMessOnEvent(note, tick+2, ACTIVATENOTE));
				track.add(createMetaMessOnEvent(note+4, tick+3, DESACTIVATENOTE));
				track.add(createMetaMessOnEvent(note, tick+3, DESACTIVATENOTE));
			}
			this.setSequence(seq);
			setTempo(tempo);
		} catch (InvalidMidiDataException e) {
			throw new Exception(e); 
		}
	}

	public String getIndication() {
		return "no indication";
	}

}
